<script lang="ts" setup>
import { reactive } from 'vue';
import { loginUsingPost, registerUsingPost } from "@/api/userController";
import { useLoginUserStore } from "@/stores/UseLoginUserStore";
import { message } from "ant-design-vue";
import { useRouter } from "vue-router";

const loginUserStore = useLoginUserStore()
const router = useRouter()

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}

const formState = reactive<API.UserRegisterRequest>({
  userAccount: '',
  userPassword: '',
  checkPassword: ''
});

const handleSubmit = async (values: any) => {
  try {
    const res = await registerUsingPost(values)
    if (res.data.code === 0 && res.data.data) {
      message.success('注册成功')
      router.push({
        path: '/user/login',
        replace: true
      })
    } else {
      message.error('注册失败')
    }
  } catch (e: any) {
    message.error('注册失败' + e.message)
  }
};
</script>

<template>
  <div class="register-container">
    <div class="glassmorphism-card">
      <h2 class="gradient-title">企业级智能协同云图库</h2>
      <div class="sub-title">开启您的智能视觉资产管理之旅</div>

      <a-form
          :model="formState"
          class="custom-form"
          @finish="handleSubmit"
      >
        <a-form-item
            name="userAccount"
            :rules="[{ required: true, message: '请输入账号!' }]"
        >
          <a-input
              v-model:value="formState.userAccount"
              placeholder="请输入账号"
              class="custom-input"
          >
            <template #prefix>
              <user-outlined class="input-icon" />
            </template>
          </a-input>
        </a-form-item>

        <a-form-item
            name="userPassword"
            :rules="[{ required: true, message: '请输入密码!' }]"
        >
          <a-input-password
              v-model:value="formState.userPassword"
              placeholder="请输入密码"
              class="custom-input"
          >
            <template #prefix>
              <lock-outlined class="input-icon" />
            </template>
          </a-input-password>
        </a-form-item>

        <a-form-item
            name="checkPassword"
            :rules="[{ required: true, message: '请再次输入密码!' }]"
        >
          <a-input-password
              v-model:value="formState.checkPassword"
              placeholder="确认密码"
              class="custom-input"
          >
            <template #prefix>
              <safety-certificate-outlined class="input-icon" />
            </template>
          </a-input-password>
        </a-form-item>

        <a-form-item>
          <a-button
              type="primary"
              html-type="submit"
              class="submit-btn"
          >
            <template #icon><rocket-outlined /></template>
            立即注册
          </a-button>
        </a-form-item>

        <div class="action-links">
          已有账户？
          <router-link to="/user/login" class="link-highlight">立即登录</router-link>
        </div>
      </a-form>
    </div>

    <div class="decorative-circle circle-1"></div>
    <div class="decorative-circle circle-2"></div>
  </div>
</template>

<style scoped lang="less">
// 颜色变量
@primary-color: #1890ff;
@gradient-start: #2c3e50;
@gradient-end: #3498db;
@glass-background: rgba(255, 255, 255, 0.95);
@shadow-color: rgba(0, 0, 0, 0.1);

.register-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;

  .glassmorphism-card {
    background: @glass-background;
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1;
  }

  .gradient-title {
    text-align: center;
    background: linear-gradient(135deg, @gradient-start, @gradient-end);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 28px;
    margin-bottom: 8px;
  }

  .sub-title {
    text-align: center;
    color: lighten(@gradient-start, 20%);
    margin-bottom: 40px;
    font-size: 16px;
  }

  .custom-form {
    .custom-input {
      border-radius: 12px;
      padding: 12px 16px;
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

      &:hover {
        border-color: @primary-color;
      }

      &:focus {
        box-shadow: 0 0 0 2px fade(@primary-color, 20%);
      }

      .input-icon {
        color: fade(@gradient-start, 60%);
        margin-right: 8px;
      }
    }

    .submit-btn {
      width: 100%;
      height: 48px;
      font-size: 16px;
      border-radius: 12px;
      background: linear-gradient(135deg, @primary-color, darken(@primary-color, 10%));
      border: none;
      transition: transform 0.3s ease;

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px fade(@primary-color, 30%);
      }
    }
  }

  .action-links {
    text-align: center;
    margin-top: 24px;
    color: lighten(@gradient-start, 20%);

    .link-highlight {
      color: @primary-color;
      font-weight: 500;
      transition: all 0.3s ease;

      &:hover {
        color: darken(@primary-color, 10%);
      }
    }
  }

  .decorative-circle {
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(135deg, fade(@primary-color, 10%), transparent);
    filter: blur(30px);

    &.circle-1 {
      width: 300px;
      height: 300px;
      top: -50px;
      left: -100px;
    }

    &.circle-2 {
      width: 200px;
      height: 200px;
      bottom: -50px;
      right: -80px;
    }
  }
}

// 响应式调整
@media (max-width: 768px) {
  .register-container {
    padding: 20px;

    .glassmorphism-card {
      padding: 30px;
      margin: 20px;
    }

    .gradient-title {
      font-size: 24px;
    }
  }
}
</style>
